#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int inf = 0x3f3f3f3f;
const int N = 4e4+10;

int cnt = 1,h[N],incf[N],r[N],f,m,n_,p,s,S,T,dis[N],pre[N],n;
ll cost;
bool vis[N];

struct edge{int v,w,c,nxt;}e[N<<4];

void link(int x,int y,int w,int c){e[++cnt] = (edge){y,w,c,h[x]};h[x] = cnt;e[++cnt] = (edge){x,0,-c,h[y]};h[y] = cnt;}

bool spfa(){
	memset(dis,0x3f,sizeof(dis)); queue<int> q; q.push(S); dis[S] = 0; incf[S] = inf; memset(vis,0,sizeof(vis)); vis[S] = 1;
	while(q.size()){
		int x = q.front(); q.pop(); 
		for(int i = h[x],y;i;i = e[i].nxt){
			if(dis[y = e[i].v] > dis[x] + e[i].c && e[i].w > 0){
				dis[y] = dis[x] + e[i].c; incf[y] = min(incf[x],e[i].w); pre[y] = i;
				if(!vis[y]) q.push(y),vis[y] = 1;
			}
		}vis[x] = 0;
	}return incf[T] >= 0 && dis[T] < inf;
}

void update(){
	int x = T;
	while(x != S){
		int i = pre[x]; e[i].w -= incf[T]; e[i^1].w += incf[T];
		x = e[i^1].v;
	}
	cost += (ll) incf[T] * dis[T];
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in;
	for(int i = 1;i <= n;i++) r[i] = in;
	p = in,m = in,f = in,n_ = in,s = in;
	S = 0,T = n * 2 + 1;
	for(int i = 1;i <= n;i++){
		link(S,i,r[i],0); link(i+n,T,r[i],0);
		if(i < n) link(i,i+1,inf,0); if(i + m <= n) link(i,i+m+n,inf,f);
		if(i + n_ <= n) link(i,i+n_+n,inf,s); link(S,i+n,inf,p);
	}
	while(spfa()) update();
	printf("%lld\n",cost);
	return 0;
}

